let disp = require("../../../../utils/broadcast");
var app = getApp()
var interval;
var time1 = null
Page({
  data: {
    upload_picture_list: [],
    typedate: 0,
    username: {
      your: "",
    },
    shouwtab: false,
    show: !0,
    hide: !1,
    xing: 0,
    evaluate: true,
    figure: 0, // 0 患者     1 医生
    dex: "", //1 处方  ！1不是
    imgs: [],
    list: [],
    isaddshow: true
  },

  //关闭追问
  closezhuiwen() {
    this.setData({
      shouwtab: false
    })
  },
  // 订单完成
  succ:function(e){
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content:'确认订单已完成吗？',
      success:function(con)
      {
        if(con.confirm)
        {
          app.util.request({
            'url':"entry/wxapp/green.over_order",
            data:{
              id:id,
            },
            success:function(res){
              wx.showToast({
                title: '操作成功',
              })
              setTimeout(() => {
                wx.navigateBack({
                  complete: (res) => {},
                })
              }, 1000);
            }
          })
        }
      }

    })
  },
  //提交追问
  submitformzw(e) {
    var that = this;
    var val = e.detail.value.zhuiwen;
    var upload_picture_list = that.data.upload_picture_list
    var typedate = that.data.typedate
    var back_orser = that.data.back_orser;
    var arr = {
      'text': val,
      'typedate': typedate,
      'upload_picture_list': upload_picture_list,
    }
    app.util.request({
      'url': 'entry/wxapp/green.guidance_reply',
      data: {
        arr: arr,
        back_orser: back_orser,
      },
      success: function (res) {
        //console.log(res)
        that.getOrder_detail()
        that.setData({
          shouwtab: false
        })
      }
    })
  },
  //图片上传
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              //console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  // 删除图片
  clearImg: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.ind;
    //console.log(index);
    var nowList = []; //新数据
    var imglis = that.data.upload_picture_list; //原数据
    imglis.splice(index, 1);
    that.setData({
      upload_picture_list: imglis
    })
  },
  // 图片预览
  previewImage: function (e) {
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.upload_picture_list
    })
  },
  // 关闭评价
  closeevaluate() {
    this.setData({
      evaluate: false
    })
  },
  // 评分
  xingclick(e) {
    let num = this.data.xing
    if (e.currentTarget.dataset.type == 'a') {
      this.setData({
        xing: e.currentTarget.dataset.num
      })
    } else {
      this.setData({
        xing: e.currentTarget.dataset.num + num
      })
    }
  },
  // 发布提问
  submitform(e) {
    let vals = e.detail.value.liuyan;
  },
  // options = 系统传入的 url 参数
  onLoad(options) {
    //console.log(options)
    var that = this
    var id = options.id
    var did = options.did;
    var typedate = options.typedate
    var key_words = options.key_words
    var openid = options.openid
    var ifpay = options.ifpay
    var docindex = options.docindex
    if (options.j_id) {
      var j_id = options.j_id
      app.util.request({
        'url': 'entry/wxapp/user.detail',
        data: {
          j_id: j_id
        },
        success: function (res) {
          console.log(res)
          that.setData({
            usedetail: res.data
          })
        }
      })
      that.setData({
        j_id: options.j_id
      })
    }
    if (options.back_orser) {
      var back_orser = options.back_orser
      var openid = options.openid
      that.setData({
        back_orser: back_orser,
        openid: openid
      })
    }

    that.setData({
      id: id,
      did: did,
      key_words: key_words,
      ifpay: ifpay,
      back_orser: back_orser,
      docindex: docindex
    })
    that.getOrder_detail();
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        //console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
  },
  getOrder_detail: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.order_detail",
      data: {
        id: that.data.id
      },
      success: function (res) {
        if(res.data.ifpay != '2' && res.data.ifpay != '5')
        {
          clearInterval(time1)
        }
        that.setData({
          list: res.data
        })
        console.log(that.data.list);
      }
    })
  },
  jiezhen: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var did = that.data.did
    wx.showModal({
      title: '提示',
      content: "是否确认接诊",
      success: function (con) {
        if (con.confirm) {
          app.util.request({
            'url': "entry/wxapp/green.order_accept",
            data: {
              id: id,
              did: did
            },
            success: function (res) {
              wx.showModal({
                title: '提示',
                content: res.data.message,
                showCancel: false,
                success: function (res) {
                  that.setData({
                    page: 0,
                    list: []
                  })
                  that.getOrder_detail();
                }
              })

            }
          })
        }

      }
    })

  },
  onShow: function (e) {
    var that = this
    that.getUptotime()
    wx.showNavigationBarLoading();
    
    
  },
  getUptotime() {
    var that = this
    wx.showNavigationBarLoading();
    time1 = setInterval(function () {
      that.getOrder_detail()
    }, 1000)
    wx.showNavigationBarLoading();
  },
  onHide: function () {

  },
  onUnload() {
    clearInterval(time1)
    var that = this
    var currentData = that.data.currentData
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    that.setData({
      currentData: currentData
    })
  },
  onPullDownRefresh: function () {

  },


  clickshow: function (t) {
    this.setData({
      show: !0,
      hide: !1
    });
  },
  clickshow1: function (t) {
    this.setData({
      show: !1,
      hide: !0
    });
  },
  tabinput2(e) {
    var that = this
    that.setData({
      shouwtab: !this.data.shouwtab
    })
  },

  previewImg: function (t) {
    //console.log(t)
    var current = t.target.dataset.src;
    //预览图片
    var imgs = []
    imgs.push(current)
    wx.previewImage({
      current: current,
      urls: imgs,
    });
  },
});